const ReactRefreshPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const px2rem = require('postcss-px2rem-exclude');

module.exports = {
  entry: './index.js',
  resolve: {   // 需要打包的文件后缀
    extensions: [".tsx", ".ts", '.jsx', ".js"]
  },
  module: {
    rules: [
      {
        test: /\.(js|ts)x?$/,
        exclude: /node_modules/,
        loader: 'babel-loader',
        options: {
          presets: ['@babel/env', '@babel/preset-react', '@babel/preset-typescript'],
          plugins: [require.resolve('react-refresh/babel')], // 为 react-refresh 添加
        },
      },
      {
        test: /\.(scss|css)$/,
        use: ["style-loader", "css-loader", {
          loader: 'postcss-loader',
          options: {
            plugins: [
              px2rem({
                remUnit: 75
            })]
          }
        },
        "sass-loader",],
      }
    ],
  },
  plugins: [
    new ReactRefreshPlugin(),    // 为 react-refresh 添加
    new HtmlWebpackPlugin({
      template: './index.html',
    }),
  ],
};
